<template>
	<view class="container">
		<uni-nav-bar class="ch-nav" height="88rpx" backgroundColor="#ffffff" leftWidth="90rpx" rightWidth="90rpx" color="#333" :fixed="true" :padding="false" :border="false" @clickLeft="$goBack(1)">
			<template slot="left">
				<image class="left" src="@/public/images/public/dhl_fhjt.png" mode="aspectFit"></image>
			</template>
			<text class="title">重置支付密码</text>
			<template slot="right">
			</template>
		</uni-nav-bar>
		<view class="body flex-c" v-if="!success">
			<form ref="form">
				<view class="input_box code flex-r">
					<input class="input" type="number" placeholder="请输入新的支付密码" placeholder-style="color:#B3B3B3;font-size:30rpx" v-model="payPwd" maxlength="6"/>
				</view>
				<view class="message flex-r">
					<text>请输入新的6位数字密码，确认后生效</text>
				</view>
				<view class="submit-box">
					<button type="default" class="nextbtn" :class="{'active': canSubmit}" @tap="submit" :loading="loading">确认</button>
				</view>
			</form>
		</view>
		<view class="body result flex-c ac" v-else>
			<view class="success flex-c ac">
				<image src="@/public/images/public/zfcg.png" mode="aspectFit"></image>
				<text class="title">重置成功</text>
				<text class="reson">支付密码已经重置成功</text>
			</view>
			<view class="submit-box">
				<button type="default" class="nextbtn active" @tap="back">返回</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				smscode: null,
				isSubmit: false,
				loading: false,
				payPwd: '',
				success: false,
			}
		},
		computed:{
			user() {
				return this.$store.state.user
			},
			canSubmit() {
				return this.payPwd != '' && this.payPwd.length == 6
			}
		},
		onLoad() {
			if(this.$Route.query.smscode){
				this.smscode = this.$Route.query.smscode
			}
		},
		methods: {
			//登录提交
			submit(){
				if(this.isSubmit || !this.canSubmit) {
					return
				}
				if(!this.smscode){
					uni.showToast({
						title: '您还没有获取验证码',
						icon: 'none'
					})
					return
				}
				this.isSubmit = true
				this.loading  = true
				let userPwdModel = {
					smscode: this.smscode,
					newPayPwd: this.payPwd,
					userId: this.user.userId,
				}
				this.$http.post({
					url: '/api/appUser/forgetPayPwd',
					data: {
						...userPwdModel
					},
				}).then(data => {
					console.log(data);
					this.loading = false
					if(data.success){
						//uni.setStorageSync('payPwd', 1)
						uni.showToast({
							title: '密码重置成功',
							icon: 'success',
							duration: 1000
						})
						this.success = true
					}else{
						this.isSubmit = false
						uni.showToast({
							title: data.message,
							icon: 'none'
						})
					}
				}).catch((err) => {
						console.log(err);
						this.isSubmit = false
						this.loading = false
				})
			},
			//返回
			back() {
				this.$Router.back(1)
			}
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 0;
		.body {
			margin: 20rpx 0 0;
			align-items: center;
			width: 100%;
			.input_box{
				width: 710rpx;
				padding: 0 20rpx;
				background: #FFFFFF;
				.input{
					border: none;
					width: 100%;
					height: 96rpx;
				}
			}
			.message{
				margin: 20rpx 20rpx 0;
				font-size: 26rpx;
				line-height: 26rpx;
				color: #999;
			}
			.submit-box{
				margin: 40rpx 20rpx 0;
			}
			&.result{
				margin: 20rpx;
				width: 710rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				.success{
					margin-top: 60rpx;
					image{
						width: 320rpx;
						height: 200rpx;
					}
					.title{
						font-size: 36rpx;
						font-weight: 500;
						margin-top: 30rpx;
					}
					.reson{
						margin-top: 20rpx;
						font-size: 26rpx;
						color: #999999;
					}
				}
				.submit-box{
					width: 560rpx;
					margin: 60rpx auto;
				}
			}
		}
	}
</style>
